package com.wpp.test;


//增加同步监视器，保证线程安全
public class tocketTestThread extends Thread {

    public static int tocket=3;
    @Override
    public  void run() {

        while (true){
            synchronized (tocketTestThread.class){
            try {
                sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
                if (tocket>0){

                    System.out.println(Thread.currentThread().getName()+" "+tocket);
                    tocket--;
                }else {
                    break;
                }
            }
        }

    }


    public static void main(String args[]) {
        tocketTestThread t1 = new tocketTestThread();
        tocketTestThread t2 = new tocketTestThread();
        tocketTestThread t3 = new tocketTestThread();

        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");

        t1.start();
        t2.start();
        t3.start();
    }
}
